package com.kl.drs.util;
/**
 * 视频转换工具类
 * @author admin
 * @param videoFilePath 视频文件的路径
 * @parm mp4Path 转换成MP4的存放的路径
 * @parm ffmpegPath ffmpeg安装的路径
 * @return exitValue
 */
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class VideoConvertUtil {
	public static boolean processFLV(String videoFilePath,String mp4Path,String ffmpegPath) {  
    	List<String> command = new ArrayList<String>();  
        command.add(ffmpegPath);  
        command.add("-i");  
        command.add(videoFilePath);
        command.add("-ab");  
        command.add("56");  
        command.add("-ar");  
        command.add("22050");  
        command.add("-qscale");  
        command.add("8");  
        command.add("-r");  
        command.add("15"); 
        command.add("-s");  
        command.add("1920x1024");  
        //command.add(outputPath + "h.mp4");
        command.add(mp4Path+ ".flv");
  
        try {  
            Process videoProcess = new ProcessBuilder(command).redirectErrorStream(true).start();  
              
            new PrintStream(videoProcess.getErrorStream()).start();  
              
            new PrintStream(videoProcess.getInputStream()).start();  
              
            videoProcess.waitFor();  
              
            return true;  
        } catch (Exception e) {  
            e.printStackTrace();  
            return false;  
        }  
    }  
}  
  
class PrintStream extends Thread   
{  
    java.io.InputStream __is = null;  
    public PrintStream(java.io.InputStream is)   
    {  
        __is = is;  
    }   
  
    public void run()   
    {  
        try   
        {  
            while(this != null)   
            {  
                int _ch = __is.read();  
                if(_ch != -1)   
                    System.out.print((char)_ch);   
                else break;  
            }  
        }   
        catch (Exception e)   
        {  
            e.printStackTrace();  
        }   
    }  
		
}
